//
//  CustomFeatureCell.h
//  IceBreaker
//
//  Created by 老焦 on 12-10-16.
//  Copyright (c) 2012年 NDS. All rights reserved.
//

#import "CustomFeatureCell.h"
#import "QuartzCore/CALayer.h"

#define SELF_WIDTH 320.0f
#define GAP_WIDTH 7.0f
#define EVENT_IMG_WIDTH 306.0f
#define EVENT_IMG_HEIGHT 170.0f
#define HEAD_IMG_SIDE 50.0f
#define ICON_SIDE 12.0f

@implementation CustomFeatureCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(id) initWithEventImg: (UIImage *)eventIcon
               headImg: (UIImage *)headIcon
            eventTitle: (NSString *)title
                  name: (NSString *)name
                gender: (int) gender
                   age: (int)age
             eventType: (NSString *)type
              distance: (float)distance
       reuseIdentifier: (NSString *)reuseIdentifier; {
    self = [super initWithStyle: UITableViewCellStyleDefault
                reuseIdentifier: reuseIdentifier];
    if (self) {
        UIView *cellView = [[UIView alloc] initWithFrame: CGRectMake(GAP_WIDTH, GAP_WIDTH, EVENT_IMG_WIDTH, 242)];
        cellView.layer.shadowColor = [UIColor purpleColor].CGColor;
        cellView.layer.shadowOffset = CGSizeMake(0, 1);
        cellView.layer.shadowOpacity = 1;
        cellView.layer.shadowRadius = 3.0;
        cellView.clipsToBounds = NO;
        
        UIImageView *eventImg = [[UIImageView alloc] initWithFrame: CGRectMake(0, 0, EVENT_IMG_WIDTH, EVENT_IMG_HEIGHT)];
        eventImg.image = eventIcon;
        [cellView addSubview: eventImg];
        [eventImg release];
        
        UIImageView *headImg = [[UIImageView alloc] initWithFrame: CGRectMake(7, EVENT_IMG_HEIGHT + 5, HEAD_IMG_SIDE, HEAD_IMG_SIDE)];
        headImg.image = headIcon;
        headImg.layer.masksToBounds = YES;
        headImg.layer.cornerRadius = 5.0;
        [cellView addSubview: headImg];
        [headImg release];
        
        UILabel *titleLabel = [[UILabel alloc] initWithFrame: CGRectMake(62, EVENT_IMG_HEIGHT + 5, 240, HEAD_IMG_SIDE)];
        titleLabel.font = [UIFont systemFontOfSize: 12];
        titleLabel.numberOfLines = 0;
        titleLabel.text = title;
        [cellView addSubview: titleLabel];
        [titleLabel release];
        
        UIFont *font = [UIFont systemFontOfSize: 10.0f];
        // UIFont *font = [UIFont fontWithName: @"Noteworthy" size:10.0f];
        UILabel *nameLabel = [[UILabel alloc] initWithFrame: CGRectMake(GAP_WIDTH, 227, HEAD_IMG_SIDE, ICON_SIDE)];
        nameLabel.font = font;
        nameLabel.textAlignment = UITextAlignmentCenter;
        nameLabel.numberOfLines = 0;
        nameLabel.text = name;
        [cellView addSubview: nameLabel];
        [nameLabel release];
        
        UIImageView *genderImg = [[UIImageView alloc] initWithFrame: CGRectMake(62, 227, ICON_SIDE, ICON_SIDE)];
        if (gender == 1) {
            genderImg.image = [UIImage imageNamed: @"male.png"];
        } else {
            genderImg.image = [UIImage imageNamed: @"female.png"];
        }
        [cellView addSubview: genderImg];
        [genderImg release];
        
        UILabel *ageTitle = [[UILabel alloc] initWithFrame: CGRectMake(76, 227, 28, ICON_SIDE)];
        ageTitle.font = font;
        ageTitle.text = [NSString stringWithFormat: @"%d", age];
        [cellView addSubview: ageTitle];
        [ageTitle release];
        
        UILabel *typeTitle = [[UILabel alloc] initWithFrame: CGRectMake(174, 227, 60, ICON_SIDE)];
        typeTitle.font = font;
        typeTitle.textAlignment = UITextAlignmentRight;
        typeTitle.text = type;
        [cellView addSubview: typeTitle];
        [typeTitle release];
        
        UIImageView *distanceImg = [[UIImageView alloc] initWithFrame: CGRectMake(240, 227, ICON_SIDE, ICON_SIDE)];
        distanceImg.image = [UIImage imageNamed: @"marker.png"];
        [cellView addSubview: distanceImg];
        [distanceImg release];
        
        UILabel *distanceTitle = [[UILabel alloc] initWithFrame: CGRectMake(255, 227, 47, ICON_SIDE)];
        distanceTitle.font = font;
        distanceTitle.textAlignment = UITextAlignmentLeft;
        distanceTitle.text = [NSString stringWithFormat: @"%0.1fkm", distance];
        [cellView addSubview: distanceTitle];
        [distanceTitle release];
        
        [cellView setBackgroundColor: [UIColor whiteColor]];
        [self addSubview: cellView];
        self.frame = CGRectMake(0, 0, SELF_WIDTH, 254);
        
        // self.contentView.backgroundColor = [UIColor redColor];
    }
    return self;
}

@end
